#!/bin/bash

# Slackware build script for cryptokwot

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=cryptokwot
VERSION=${VERSION:-0.0.3}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

ARCH=noarch

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

# No "source" directory needed. The executable spits out its own man page,
# .desktop file, and icon, so give it a short name:
P=$PKG/usr/games/$PRGNAM

rm -rf $PKG
mkdir -p \
  $PKG/usr/{games,man/man6,share/{icons/hicolor/64x64/apps,applications}} \
  $OUTPUT
install -oroot -groot -m0755 $CWD/$PRGNAM $P

$P --man     | gzip -9c > $PKG/usr/man/man6/$PRGNAM.6.gz
$P --icon    | convert gif:- png32:$PKG/usr/share/icons/hicolor/64x64/apps/$PRGNAM.png
$P --desktop > $PKG/usr/share/applications/$PRGNAM.desktop

PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
mkdir -p $PKGDOC
cat $CWD/README > $PKGDOC/README
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
